﻿CREATE TABLE [dbo].[Customer](
	[Id] UNIQUEIDENTIFIER NOT NULL,
	[Name] VARCHAR(100) NULL,
	[Created] DATETIME,
	[ContactNumber] VARCHAR(15) NULL,
	[Email] VARCHAR(50) NULL,
	[AddressId] UNIQUEIDENTIFIER
)
GO
ALTER TABLE [dbo].[Customer] ADD CONSTRAINT [pk_Customer_Id] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Address](
	[Id] UNIQUEIDENTIFIER NOT NULL,
	[HouseName] VARCHAR(50) NULL,
	[HouseNumber] INT NULL,
	[Line1] VARCHAR(100),
	[Line2] VARCHAR(100) NULL,
	[Town] VARCHAR(50),
	[County] VARCHAR(50),
	[PostCode] VARCHAR(10)
)
GO
ALTER TABLE [dbo].[Address] ADD CONSTRAINT [pk_Address_Id] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Product](
	[Id] UNIQUEIDENTIFIER NOT NULL,
	[Cost] DECIMAL,
	[Name] VARCHAR(100)
)
GO
ALTER TABLE [dbo].[Product] ADD CONSTRAINT [pk_Product_Id] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Order](
	[Id] UNIQUEIDENTIFIER NOT NULL,
	[Name] VARCHAR(100) NULL,
	[CustomerId] UNIQUEIDENTIFIER,	
)
GO
ALTER TABLE [dbo].[Order] ADD CONSTRAINT [pk_Order_Id] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO


CREATE TABLE [dbo].[OrderProducts](
	[Id] UNIQUEIDENTIFIER NOT NULL,
	[ProductId] UNIQUEIDENTIFIER,
	[OrderId] UNIQUEIDENTIFIER
)
GO
ALTER TABLE [dbo].[OrderProducts] ADD CONSTRAINT [pk_OrderProducts_Id] PRIMARY KEY CLUSTERED  ([Id]) ON [PRIMARY]
GO

CREATE PROCEDURE [dbo].[DeleteAllData] 
AS
BEGIN
	SET NOCOUNT ON;
	EXEC sp_MSForEachTable 'DELETE FROM ?'
END
GO
